'use strict';
const uniPush = uniCloud.getPushManager({
	appId: "__UNI__F933AD4"
}) //注意这里需要传入你的应用appId
exports.main = async (event, context) => {
	console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
	// console.log(JSON.stringify(event));
	// console.log(JSON.stringify(context));
	console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
	let body = '';
	if (event.body) {
		body = JSON.parse(event.body)
	}
	if (!body) {
		return {
			code: 1,
			msg: '数据格式不正确'
		}
	}
	if (body && body.push_clientid && (body.cmd == 2) || (body.cmd == 5)) {
		// 群聊和单聊消息
		// return body;
		let title = body.name;
		let content = body.content;
		if (body.groupName) {
			title = body.groupName;
		}

		return await uniPush.sendMessage({
			push_clientid: body.push_clientid,
			group_name: String(body.id),
			title: title,
			content: content,
			force_notification: true,
			badge: '+1',
			payload: {
				...body
			},
			// option:{
			// 	icon:body.avatarUrl || body.toAvatarUrl,
			// 	cover:true,
			// },
			options:{
				icon:body.avatarUrl || body.toAvatarUrl,
				cover:true,
			},
			// icon:body.avatarUrl || body.toAvatarUrl,
			// cover:true,
		})

	}
	return body;


};
